﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>JSON Data Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <div id="jsonResult"></div> <!-- 用于显示 JSON 数据的 div 元素 -->
        </div>

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        <script type="text/javascript">
            // 使用AJAX请求从服务器获取JSON数据
            $(document).ready(function () {
                $.ajax({
                    type: "GET",
                    url: "Default.aspx/GetJSONData", // 假设这是后端提供JSON数据的服务端方法
                    contentType: "text/html;charset=utf-8",
                    dataType: "json",
                    success: function (data) {

                        // 显示 JSON 数据在页面上
                        var jsonResult = $("#jsonResult");
                        jsonResult.text("JSON Data: " + JSON.stringify(data));
                    },
                    error: function (error) {
                        console.log("Error: " + error);
                    }
                });
            });
        </script>
        <script type="text/javascript">
            $(document).ready(function () {
                // 准备要发送的登录数据
                var loginData = {
                    username: "admin",
                    password: "1"
                };

                $.ajax({
                    type: "POST",
                    url: "http://tempuri.org/login/", // 替换成你的登录接口的URL
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data: JSON.stringify(loginData),
                    success: function (response) {
                        var jsonResult = $("#jsonResult");
                        jsonResult.text("Login Response: " + JSON.stringify(response));
                    },
                    error: function (error) {
                        console.log("Error: " + error);
                    }
                });
            });
        </script>

    </form>
</body>
</html>
